package com.css.dzj.dzjportal.modules.jgaction.forceAction.service.impl;

import com.css.dzj.dzjportal.common.util.excel.ExcelData;
import com.css.dzj.dzjportal.common.util.excel.ExportExcelUtils;
import com.css.dzj.dzjportal.modules.jgaction.forceAction.service.ForceService;
import com.css.dzj.dzjportal.modules.jgaction.forceAction.vo.ApJgxxForceEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author WT
 * @Date 2020/4/30
 */
@Service
public class ForceImpl implements ForceService {
    @Autowired
    private HttpServletRequest request;
    /**
     * 多条件导出
     * @param response
     * @param forceList
     */
    @Override
    public void exportForceToExcel(HttpServletResponse response, List<ApJgxxForceEntity> forceList) {

        if (forceList == null || forceList.size() < 0) {
            throw new RuntimeException("强制行为为空");
        }
        // 创建导出实体
        ExcelData data = new ExcelData();
        data.setName("强制行为");
        /**
         * 设置Excel标题
         */
        ArrayList<String> titles = new ArrayList<>();
        titles.add("记录唯一标识");
        titles.add("监管事项目录编码");
        titles.add("强制行为名称");
        titles.add("强制行为编号");
        titles.add("实施机构");
        data.setTitles(titles);
        /**
         * 处理行数据
         */
        ArrayList<List<Object>> rows = new ArrayList<>();
        for (ApJgxxForceEntity forceEntity : forceList) {
            ArrayList<Object> row = new ArrayList<>();
            row.add(forceEntity.getRecordUniqueIdentity());
            row.add(forceEntity.getSuperviseId());
            row.add(forceEntity.getForceActionName());
            row.add(forceEntity.getForceActionCode());
            row.add(forceEntity.getImplementInstitution());
            rows.add(row);
        }
        data.setRows(rows);
        try {
            // 导出
            ExportExcelUtils.exportExcel(request,response, "强制行为.xlsx", data);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
